package com.codedancer.campus.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.po.User;
import com.codedancer.campus.qo.user.UserPageSearchQo;
import java.util.List;
import org.apache.ibatis.annotations.Param;

public interface UserMapper extends BaseMapper<User> {

    /**
     * 分页查询用户
     *
     * @param userPage
     * @param userPageSearchQo
     * @return
     */
    IPage<User> page(Page<User> userPage,
        @Param("userPageSearchQo") UserPageSearchQo userPageSearchQo);

    /**
     * 查询需要导出的用户数据
     *
     * @param userPageSearchQo
     * @return
     */
    List<User> listExportUser(@Param("userPageSearchQo") UserPageSearchQo userPageSearchQo);

    /**
     * 判断昵称是否被使用(已设置基本信息的)
     *
     * @param nickName
     * @return
     */
    default boolean existsNickNameAndSetBasicMessage(String nickName) {
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(User::getNickName, nickName);
        lambdaQueryWrapper.eq(User::getIsSetBasicMessage, true);
        return selectCount(lambdaQueryWrapper) > 0;
    }
}
